package xuecheng.tool.mq.rabbitmq.delay;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * 延时消息发送处理器
 *
 * 大前提: 安装了 rabbitmq_delayed_message_exchange 插件
 *
 * @author PengXueCheng
 * @version 1.0.0
 **/
public class DealyedMessagePostProcessor implements MessagePostProcessor {

    /**
     * 消息发送的延时时长, 单位为毫秒
     */
    private int delay;

    /**
     *
     * @param delay
     *            消息发送的延时时长, 单位为毫秒
     */
    public DealyedMessagePostProcessor(int delay) {
        this.delay = delay;
    }

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setHeader("x-delay", delay);
        return message;
    }

}
